<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<!--<div class="layui-form-item">
								<label class="layui-form-label">等级状态:<span style="color:red">*</span></label>
								<div class="layui-input-block on_off"></div>
							</div>-->
							<div class="layui-form-item">
								<!--<div class="layui-inline">
									<label class="layui-form-label">级别：</label>
									<div class="layui-input-block">
										<input type="text" name="grade"  lay-verify="number | required"  class="layui-input" id="grade" autocomplete="off" placeholder="级别">
									</div>   
								</div>-->
								<div class="layui-inline">
									<label class="layui-form-label">等级名称：</label>
									<div class="layui-input-block">
										<input type="text" name="name" lay-verify="required" class="layui-input" id="name" autocomplete="off" placeholder="等级名称">
									</div>  
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">时长：</label>
									<div class="layui-input-block">
										<input type="text" name="month" lay-verify="required" class="layui-input" id="month" autocomplete="off" placeholder="时长">
									</div>  
								</div>
							</div>
							
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">标题：</label>
									<div class="layui-input-block">
										<input type="text" name="title" lay-verify="required" class="layui-input" id="title" autocomplete="off" placeholder="标题">
									</div>  
								</div>
									<div class="layui-inline">
									<label class="layui-form-label">标题简称：</label>
									<div class="layui-input-block">
										<input type="text" name="title_cn" class="layui-input" id="title_cn" autocomplete="off" placeholder="标题简称">
									</div>  
								</div>
							</div>
						    <div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">积分要求：</label>
									<div class="layui-input-block">
										<input type="text" name="score"  lay-verify="number | required"   class="layui-input" id="score" autocomplete="off" placeholder="积分要求">
									</div>  
								</div>
							
								<div class="layui-inline">
								<label class="layui-form-label">折扣：</label>
									<div class="layui-input-block">
										<input type="text" name="discount"  lay-verify="number | required"   class="layui-input" id="discount" autocomplete="off" placeholder="折扣">
									</div>  
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">返红包：</label>
									<div class="layui-input-block">
										<input type="text" name="fee_packet" class="layui-input" id="fee_packet" autocomplete="off" placeholder="返红包金额">
									</div>  
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">充值金额：</label>
									<div class="layui-input-block">
										<input type="text" name="amount" class="layui-input" lay-verify="number | required"   id="amount" autocomplete="off" placeholder="充值金额">
									</div>  
								</div>
							</div> 
							
							<div class="layui-form-item">
								 <div class="layui-inline">
									<label class="layui-form-label">图标<span style="color:red">*</span></label>
									<div class="layui-input-block">
										<button type="button" class="layui-btn layui-btn-normal" onclick="choose(1)">上传图标</button><span style="color:red"><p>建议上传340*220大小图片</p></span>
										<ul class="show_img_ul" id="logo_img"></ul>
									</div>
								</div>
	
								<div class="layui-inline">
									<label class="layui-form-label">背景<span style="color:red">*</span></label>
									<div class="layui-input-block">
										<button type="button" class="layui-btn layui-btn-normal" onclick="choose(2)">上传背景</button><span style="color:red"><p>建议上传750*375大小图片</p></span>
										<ul class="show_img_ul" id="bg_img"></ul>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">等级图标<span style="color:red">*</span></label>
									<div class="layui-input-block">
										<button type="button" class="layui-btn layui-btn-normal" onclick="choose(3)">上传等级图标</button><span style="color:red"><p>建议上传340*220大小图片</p></span>
										<ul class="show_img_ul" id="num_url"></ul>
									</div>
								</div>
	
								<div class="layui-inline">
									<label class="layui-form-label">升级图标<span style="color:red">*</span></label>
									<div class="layui-input-block">
										<button type="button" class="layui-btn layui-btn-normal" onclick="choose(4)">上传升级图标</button><span style="color:red"><p>建议上传750*375大小图片</p></span>
										<ul class="show_img_ul" id="upgrade_url"></ul>
									</div>
								</div>
							</div>
						  
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">图标颜色<span style="color:red">*</span></label>
									<div class="layui-input-inline" style="width: 41.5%;">
										<input type="text" value="" placeholder="图标颜色" class="layui-input" id="info_color" name='info_color'>
									</div>
									<div class="layui-inline" style="left: -11px;">
										<div id="test-form-info"></div>
									</div>
								</div>
								
								<div class="layui-inline">
									<label class="layui-form-label">标题颜色<span style="color:red">*</span></label>
									<div class="layui-input-inline" style="width: 41.5%;">
										<input type="text" value="" placeholder="标题颜色" class="layui-input" id="title_color" name='title_color'>
									</div>
									<div class="layui-inline" style="left: -11px;">
										<div id="test-form-title"></div>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">升级颜色<span style="color:red">*</span></label>
									<div class="layui-input-inline" style="width: 41.5%;">
										<input type="text" value="" placeholder="升级颜色" class="layui-input" id="up_color" name='up_color'>
									</div>
									<div class="layui-inline" style="left: -11px;">
										<div id="test-form-up"></div>
									</div>
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">排序：</label>
								<div class="layui-input-block">
									<input type="text" name="oid" class="layui-input" id="oid" autocomplete="off" placeholder="排序">
								</div>  
							</div>

						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id')
			}
			var _member = {
				
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'colorpicker'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					layedit = layui.layedit,
					colorpicker = layui.colorpicker;
				form = layui.form; 
				
				if(_data.id) {
					initdata();
				}
				var img_arr1 = [],//logo_img
					img_arr2 = [],//bg_img
					img_arr3 = [],//num_url
					img_arr4 = [];//upgrade_url 
					
				on_off_show('radio')
				seckill_type_show("option")
//				site_union_show("option")
				 
				
				//表单赋值
				colorpicker.render({
					elem: '#test-form-title',
					done: function(color) {
						console.log(color)
						$('#title_color').val(color);
					}
				});
				//表单赋值
				colorpicker.render({
					elem: '#test-form-info',
					done: function(color) {
						console.log(color)
						$('#info_color').val(color);
					}
				});
				//表单赋值
				colorpicker.render({
					elem: '#test-form-up',
					done: function(color) {
						console.log(color)
						$('#up_color').val(color);
					}
				});

				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.logo_img = img_arr1.join(',');
					_data.bg_img = img_arr2.join(',');
					_data.num_url = img_arr3.join(',');
					_data.upgrade_url = img_arr4.join(',');
					 
					 console.log(_data)
					//_data.img_url = img_arr2.join(',');
					layer.confirm('确定要提交数据？', function() {
						loading();
						if(_data.id) {
							submitdata(server.site_plus_edit);
						} else {
							delete _data.id
							submitdata(server.site_plus_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					$.get(server.site_plus_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.site_plus
								
								data.data.logo_img ? createli(data.data.logo_img, 'logo_img', '1') : '';
							    data.data.bg_img ? createli(data.data.bg_img, 'bg_img', '2') : '';
								data.data.num_url ? createli(data.data.num_url, 'num_url', '3') : '';
							    data.data.upgrade_url ? createli(data.data.upgrade_url, 'upgrade_url', '4') : '';
							
								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				} 
				
				window.searchdata = function(type) {
					switch(type) {
						case 'shopid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_shop.html',
								end: function() {},
								success: function() {}
							});
							break;
						case 'partner_id':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_partner.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}
				
				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				
				window.getimg = function(data, type) {
					console.log(data);
					if (data) {
						switch (type) {
							case '1':
								createli(data, 'logo_img', type)
								break;
							case '2':
								createli(data, 'bg_img', type)
								break;
							case '3':
								createli(data, 'num_url', type)
								break;
							case '4':
								createli(data, 'upgrade_url', type)
								break;
							default:
								break;
						}
					}
				}

				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除图片？', function(index) {
						switch (_type) {
							case '1':
								img_arr1.splice(i, 1)
								break;
							case '2':
								img_arr2.splice(i, 1)
								break;
							case '3':
								img_arr3.splice(i, 1)
								break;
							case '4':
								img_arr4.splice(i, 1)
								break;
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});

				}

				function createli(data, dom, type) {
					// console.log(data);
					var lihtml = '';
					switch (type) {
						case '1':
							if (data.indexOf(',') == -1) {
								img_arr1.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
									'</li>'
							}
							break;
						case '2':
							if (data.indexOf(',') == -1) {
								img_arr2.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr2.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr2.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr2[i] + ' >' +
									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
									'</li>'
							}
							break;
						case '3':
							if (data.indexOf(',') == -1) {
								img_arr3.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr3.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr3.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr3[i] + ' >' +
									'<p onclick="delimg(' + i + ',3,this)">删除</p>' +
									'</li>'
							}
							break;	
						case '4':
							if (data.indexOf(',') == -1) {
								img_arr4.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr4.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr4.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr4[i] + ' >' +
									'<p onclick="delimg(' + i + ',4,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}
			});
		</script>
	</body>

</html>